package cn.entity;
import cn.actionListener.*;
import cn.entity.img.Background;
import cn.entity.master.Fighter;
import cn.entity.utils.Paint;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class StartView extends JFrame {
    private JFrame frame;
    private JPanel mainPanel;
    private JLabel titleLabel;
    private JButton startButton;
    private JButton exitButton;
    private JLabel backgroundLabel;
    private ImageIcon titleImg;
    private ImageIcon background;
    private File imgFile;
    private File bgImg;
    private Background bg;
    private Paint paint;
    private JButton teach;
    private Fighter fighter;
    public StartView() {
        teach=new JButton("教程");
        frame = new JFrame("Game");
         imgFile=new File("img/title/start.png");
         bgImg=new File("img/title/start1.jpg");
        try{
            fighter=new Fighter();
             bg=new Background();
            titleImg=new ImageIcon(ImageIO.read(imgFile));
            background=new ImageIcon(ImageIO.read(bgImg));
            backgroundLabel=new JLabel(background);
            titleLabel=new JLabel(titleImg);
        }catch (IOException e){
            e.printStackTrace();
        }
        mainPanel = new JPanel(null);
        startButton=new JButton("开始游戏");
        exitButton=new JButton("退出游戏");
    }
    public void  init()  {
        frame.setSize(800,600 );
        frame.setResizable(true);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        backgroundLabel.setBounds(0,0,800,600);
        titleLabel.setBounds(150,0,500,200);
        startButton.setBounds(325,200,150,50);
        exitButton.setBounds(325,400,150,50);
        teach.setBounds(325,300,150,50);
        mainPanel.add(titleLabel);
        mainPanel.add(startButton);
        mainPanel.add(exitButton);
        mainPanel.add(teach);
        mainPanel.add(backgroundLabel);
        startButton.addActionListener(new StartListener(this,fighter));

        frame.addKeyListener(new FighterMoveListener(fighter));
        frame.addKeyListener(new AttackListener(fighter));

        exitButton.addActionListener(new ExitListener());
        teach.addActionListener(new TeachListener(this));
        frame.setFocusable(true);

        frame.requestFocusInWindow();

        frame.add(mainPanel);
    }

    public JLabel getTitleLabel() {
        return titleLabel;
    }

    public JButton getStartButton() {
        return startButton;
    }

    public JButton getExitButton() {
        return exitButton;
    }

    public JLabel getBackgroundLabel() {
        return backgroundLabel;
    }
    public JButton getTeach() {
        return teach;
    }
    public Frame getFrame(){
        return frame;
    }
    
}

